#ifndef _HASHTABLE_H
#define _HASHTABLE_H

#include <ds/list.h>

typedef struct hbucket {
    hlnode_t* head;
} hbkt_t;

#define hash_key(table, hash) (hash % (sizeof(table) / sizeof(table[0])))

#define bucket_foreach(bkt, pos, nxt, member) \
    for (pos = list_entry((bkt)->head, typeof(*pos), member); \
         pos != NULL && ({nxt = list_entry(pos->member.next, typeof(*pos), member);1;}); \
         pos = nxt)

#define hash_table_foreach(table, hash, pos, nxt, member) \
    bucket_foreach(table[hash_key(table, hash)], pos, nxt, member)

#define hash_insert(table, node, hash) \
    hlist_add(&table[hash_key(table, hash)].head, node);

#endif /* _HASHTABLE_H */